package com.gzcc.controller;

import com.gzcc.common.ResponseCode;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 描述: 登录controller
 *
 * @Author: Mr.Zhong
 * @Date: 2018/6/13
 */
@Controller
public class LoginController {
    /**
     * 描述: 登录页面
     *
     * @Author: Mr.Zhong
     * @Date: 2018/6/13
     */
    @GetMapping(value = "/login")
    public String login(Model model, HttpServletRequest request) {
        if (request.getSession().getAttribute("message") != null) {
            model.addAttribute("error", request.getSession().getAttribute("message"));
        } else {
            model.addAttribute("error", "");
        }
        return "backend/login.btl";
    }

    /**
     * 描述: 首页
     *
     * @Author: Mr.Zhong
     * @Date: 2018/6/13
     */
    @RequestMapping(value = "/")
    public String index() {
        return "backend/index.btl";
    }

    @RequestMapping(value = "/welcome")
    public String welcome(@AuthenticationPrincipal UserDetails userDetails,Model model) {
        model.addAttribute("name",userDetails.getUsername());
        return "backend/welcome.btl";
    }

}


